package com.zbkj.service.aspect;

import com.zbkj.common.exception.CrmebException;
import com.zbkj.service.util.LocalUtil;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class I18nExceptionAspect {

    @Autowired
    private LocalUtil localUtil;


    @Around("@within(org.springframework.web.bind.annotation.RestController)")
    public Object handleException(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            return joinPoint.proceed();
        } catch (CrmebException e) {
            String message = localUtil.get(e.getMessage());
            throw new CrmebException(message);
        }
    }
}